/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import dao.DAOCour;
import dao.DAOEtudiant;
import dao.DAOPersonne;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.Cour;
import model.Enseignant;
import model.Etudiant;
import model.Personne;
import utils.TypeUtilisateur;

/**
 *
 * @author Paul
 */
public class RecapNotes extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            this.doAny(request, response);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            this.doAny(request, response);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private void doAny(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        Etudiant e = (Etudiant) request.getSession().getAttribute("etudiant");
        if (e != null) {
            if (request.getSession().getAttribute("listeCours") == null) {
                DAOCour daoCour = new DAOCour();
                ArrayList<Cour> listeCours = daoCour.findCours(e.getId());
                request.getSession().setAttribute("listeCours", listeCours);
            }
            request.getRequestDispatcher("/WEB-INF/view/consultation/recapNotes.jsp").forward(request, response);

        } else {
            request.getRequestDispatcher("view/connexion/connexion.jsp").forward(request, response);
        }
    }
}
